//
//  YJTabBarController.m
//  SnackCourier
//
//  Created by qianfeng01 on 15/7/17.
//  Copyright (c) 2015年 qianfeng01. All rights reserved.
//

#import "YJTabBarController.h"
#import "YJBaseViewController.h"
@interface YJTabBarController ()
{
    UIButton *_creatViewButton;
}
@property (nonatomic)UIButton *creatViewButton;
@end

@implementation YJTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatViewControllers];
    NSMutableArray *VCArray =[[NSMutableArray alloc] init];
    
    NSArray *LabelArray =@[@"首页",@"类别",@"收藏",@"我的"];
    
    NSArray *VCNames =@[@"YJHomePageViewController",@"YJCategoryViewController",@"YJCollectionViewController",@"YJMyViewController"];
    
    for (int i=0; i<VCNames.count; i++) {
        
        Class vcClass =NSClassFromString(VCNames[i]);
        YJBaseViewController *vc =[[vcClass alloc] init];
          vc.title =LabelArray[i];
        
        UINavigationController *niv =[[UINavigationController alloc] initWithRootViewController:vc];
        [niv.navigationBar setBackgroundImage:[UIImage imageNamed:@"loginedBG"] forBarMetrics:UIBarMetricsDefault];
        [VCArray addObject:niv];
    }
    self.viewControllers =VCArray;
    self.creatViewButton =(UIButton *)[self.view  viewWithTag:101];
}

-(void)setCreatViewButton:(UIButton *)creatViewButton{
    if (_creatViewButton ==creatViewButton) {
        return;
    }
    _creatViewButton.selected =NO;
    _creatViewButton =creatViewButton;
    _creatViewButton.selected =YES;
}
-(void)creatViewControllers{
    
    self.tabBar.hidden =YES;
   
    UIImageView *image =[[UIImageView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height-49, self.view.frame.size.width, 49)];
    image.backgroundColor =[UIColor whiteColor];
    image.userInteractionEnabled =YES;
    NSArray *imagewhites =@[@"tabbar_mainPage_750@2x",@"tabbar_category_750@2x",@"tabbar_collect_750@2x",@"tabbar_mine_750@2x"];
    NSArray *imageblucks=@[@"tabbar_mainPage_HL_750@2x",@"tabbar_category_HL_750",@"tabbar_collect_HL_750@2x",@"tabbar_mine_HL_750@2x"];
    
    CGFloat with =image.frame.size.width/4.0;
    for (int i=0; i<imagewhites.count; i++) {
        UIButton *button =[UIButton buttonWithType:(UIButtonTypeCustom)];
        button.frame =CGRectMake(i*with, 0, with, 49);
        [button setBackgroundImage:[UIImage imageNamed:imagewhites[i]] forState:(UIControlStateNormal)];
        [button setBackgroundImage:[UIImage imageNamed:imageblucks[i]] forState:(UIControlStateSelected)];
        [image addSubview:button];
        button.tag =101+i;
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:(UIControlEventTouchUpInside)];
        
    }
    [self.view addSubview:image];
    
}

-(void)buttonClick:(UIButton *)button{
    self.creatViewButton = button;
    self.selectedIndex =button.tag -101;
}

@end
